package com.xiaohe66.web.gateway.http.love;

import com.xiaohe66.common.value.R;
import com.xiaohe66.web.application.love.LeaveWordAppService;
import com.xiaohe66.web.application.love.bo.MessageListBo;
import com.xiaohe66.web.application.love.bo.MessageSaveBo;
import com.xiaohe66.web.application.love.result.MessageListResult;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author xiaohe
 * @since 2021.12.07 15:45
 */
@RestController
@RequestMapping("/love/message") // TODO : 和小程序端一起将链接改成 /love/leave-word
@RequiredArgsConstructor
public class LeaveWordController {

    private final LeaveWordAppService leaveWordAppService;

    @PostMapping
    public R<MessageListResult> save(@RequestBody MessageSaveBo bo) {
        return R.ok(leaveWordAppService.save(bo));
    }

    @DeleteMapping("/{id}")
    public R<Void> delete(@PathVariable Long id) {
        leaveWordAppService.remove(id);
        return R.ok();
    }

    @GetMapping
    public R<List<MessageListResult>> list(MessageListBo bo) {
        return R.ok(leaveWordAppService.list(bo));
    }
}
